
import { createRouter, createWebHistory } from 'vue-router'
// import { useUserStore } from '@/stores/user'

// import HomeView from '../views/HomeView.vue'

// createRouter创建路由实例
// 1、history模式：createWebHistory，地址栏不带#
// 2、hash模式：createWebHashHistory，地址栏带#
const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    { 
      path: '/',component:() => import('@/views/Layout/index.vue'),
      redirect: '/home',
       children: [
        { path: '/home', component: () => import('@/views/Home/index.vue') },
        { path: '/category/:id', component: () => import('@/views/Category/index.vue') },
        { path: '/category/sub/:id', component: () => import('@/views/SubCategory/index.vue') },
        { path: '/detail/:id', component: () => import('@/views/Detail/index.vue') },
        { path: '/CartList', component: () => import('@/views/CartList/index.vue') },
        { path: '/settlement', component: () => import('@/views/settLement/index.vue') },
        { path: '/pay', component: () => import('@/views/Pay/index.vue') },
        { path: '/payback', component: () => import('@/views/Pay/payBack.vue') },
      ]
  },
// 
    { 
      path: '/login',component:() => import('@/views/Login/index.vue'),
    },
  ],
  // 路由滚动行为定制，在路由中配置上，在其他页面无论滚动多久，跳转到另一个页面立刻回到顶部
  scrollBehavior(){
    return {
      top: 0
    }
  }

})
// 登录访问拦截
// router.beforeEach(( to )=>{
//   const userStore = useUserStore()
//   // 如果没有touken，且访问的是登录页
//   if(!userStore.token && to.path !== '/login') return '/login'
// })
export default router
